import {Component, Input} from '@angular/core';
import {
    AlertController, IonicPage, LoadingController, NavController, NavParams, Platform,
    ToastController
} from 'ionic-angular';
import {ExamineApprovePage} from "../../examine/examineApprove";
import {SystemService} from "../../service/SystemService";
import {Log} from "../../../framework/utils/Log";
import {UserManager} from "../../../framework/manager/UserManager";
import {BasePage} from "../../BasePage";
import {ApplyListAPage} from "../../apply/applyList";
import {ApplyTabPage} from "../../apply/apply-tab/apply-tab";
import {ApplyStoreSLS} from "../../apply/applyStoreSLS";

/**
 * Generated class for the WaitApprovePage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */


@Component({
    selector: 'page-wait-approve',
    templateUrl: 'wait-approve.html',
    providers: [SystemService]
})
export class WaitApprovePage extends BasePage{

    private static TAG: string = 'WaitApprovePage';
    dataList: any = [];
    useId: string;
    @Input() count: string = '0';
    @Input() type: string='1';

    constructor(public navCtrl: NavController, public navParams: NavParams, public sys: SystemService, public platform: Platform,
    public loadingCtrl: LoadingController,
    public toastCtrl: ToastController,
    public alertCtrl: AlertController) {
    super(platform, loadingCtrl, toastCtrl, alertCtrl);
        this.useId = UserManager.getInstance().user.userId;
    }

    ngOnInit() {
        Log.w(WaitApprovePage.TAG, 'ngOnInit WaitApprovePage');
        this.getCheckList();
    }
    ionViewDidEnter(){
        ApplyStoreSLS.getInstance().destroy();
    }
    //获取审批列表
    getCheckList() {
        this.showLoading(true,'请稍后');
        let data: any = {
            YongHuBH: this.useId,
            RowNum: this.count,
            LeiXing: this.type
        };
        this.sys.getCheckList(data).subscribe((res: any) => {
            Log.printObj(WaitApprovePage.TAG, 'printObj==', res);
            if(res.msgCode=='1'){

                this.dataList = res.list;
            }else {
                //this.showError('数据请求失败');
            }
            this.showLoading(false,'请稍后');
        }, error => {
            this.showLoading(false,'请稍后');
            this.showError('数据请求失败');
        })
    }


    dbsqHandler(item) {
        if(this.type == "4"){
            UserManager.getInstance().user.djId = item.DanJuBH;
            this.navCtrl.push(ApplyTabPage,{data:item,type:"4"})
        }else {
            this.navCtrl.push(ExamineApprovePage,{data:item,type:this.type})

        }
    }
}
